function returnBackArea(){
    var word = $("#word").val();
    var len =  $('#site').children(".choose").length-2;
    if(len == -1){
        $('#site').html("<span class='topspan' style='position: relative;top:5px;'>请选择所在"+word+"</span>\n\
<a class='triangle' style='display: block; left: 59px;'></a>");
        $('.cities').show();
        $("#countries").hide();
    }else{
        $('#site').children(".choose").eq(len).click();
    }
      
}

        

function getCountry(id,name){
    $.post("index.php/Ajax/getArea",{
        id:id
    },function(data){
        $(".cities").hide();
        $("#countries").show();
        var len = data.length;
        var span = '';
        for(var i =0;i<len;i++){
            if(i%4 == 0){
                span +="<li>";
            }
            
            var word = $("#word").val();
        if(word == "区域"){
            var url = "Area/lists/id/"+data[i]['id']+".html";
            span += "<a href='"+url+"' target='_blank' title="+data[i]['name']+">"+data[i]['name']+"</a>";
        }else{
            span += "<span onclick=getCircleSchool("+data[i]['id']+",$(this).text())>"+data[i]['name']+"</span>";
        }
            if(i%4 == 3){
                span +="</li>";
            }
        }
        $('#countries').html(span);
        $('#site').html("<span class='topspan back' onclick=returnBackArea()></span>\n\
<span id='city' data-id="+id+" class='choose'><a class='triangle'></a>"+name+"</span>");
        getTrianglePosition('city');
        $('#circles').hide();
        $('#schools').hide();
        $('#circlesSub').hide();
    },"json")
                
}
function getTrianglePosition(id){
    var left1 = parseInt($('#site').offset().left);
    var left2 = parseInt($('#'+id).offset().left);
    var width = parseInt($('#'+id).outerWidth());
    var space = left2-left1+width/2-7;
    $('.triangle').css({
        "left":space
    });
}